/**
 * Created by Egan on 2015/1/17.
 */
module catgame{

    export class Cat extends egret.Sprite{

        public node:catgame.Node;
        private standmc:egret.MovieClip;
        private isWeizhu : boolean = false;
        private weizhumc:egret.MovieClip;

        public constructor(){
            super();
            var data=RES.getRes("stay_json");
            var texture=RES.getRes("stay_png");
            this.standmc=new egret.MovieClip(data,texture);
            this.standmc.frameRate=24;
            this.standmc.gotoAndPlay("stay");

            data=RES.getRes("weizhu_json");
            texture=RES.getRes("weizhu_png");
            this.weizhumc=new egret.MovieClip(data,texture);
            this.standmc.frameRate=24;
            this.weizhumc.gotoAndPlay("weizhu");

            this.anchorX=0.5;
            this.anchorY=1;
            this.stay();
        }

        //站定
        public stay():void{
            if(this.numChildren){
                this.removeChildAt(0);
            }
            if(this.isWeizhu){
                this.addChild(this.weizhumc);
            }else{
                this.addChild(this.standmc);
            }
        }

        public init():void{
            this.isWeizhu=false;
            this.stay();
        }

        //走一步
        public run(pos:number[]):void{
            this.x = pos[0];
            this.y=pos[1];
            this.dispatchEventWith("catRun");
        }

        public weizhu() {
            this.isWeizhu = true;
            this.stay();
        }
    }

}